<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="收房贷申请编号" prop="sfLoanOrderNo">
        <el-input
          v-model="queryParams.sfLoanOrderNo"
          placeholder="请输入收房贷申请编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外部合同号" prop="outOrderNo">
        <el-input
          v-model="queryParams.outOrderNo"
          placeholder="请输入外部合同号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外部金融产品名称，资方那边的名称" prop="outProductName">
        <el-input
          v-model="queryParams.outProductName"
          placeholder="请输入外部金融产品名称，资方那边的名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商户ID" prop="businessId">
        <el-input
          v-model="queryParams.businessId"
          placeholder="请输入商户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门编号" prop="deptNo">
        <el-input
          v-model="queryParams.deptNo"
          placeholder="请输入部门编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收房合同ID" prop="sfContractId">
        <el-input
          v-model="queryParams.sfContractId"
          placeholder="请输入收房合同ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="借款金额" prop="loanAmount">
        <el-input
          v-model="queryParams.loanAmount"
          placeholder="请输入借款金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="借款期限" prop="monthLimit">
        <el-input
          v-model="queryParams.monthLimit"
          placeholder="请输入借款期限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="利率" prop="rate">
        <el-input
          v-model="queryParams.rate"
          placeholder="请输入利率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="一次性服务费" prop="serviceFee">
        <el-input
          v-model="queryParams.serviceFee"
          placeholder="请输入一次性服务费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金融产品ID" prop="jrProductId">
        <el-input
          v-model="queryParams.jrProductId"
          placeholder="请输入金融产品ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="应收租约合计" prop="reLeaseCount">
        <el-input
          v-model="queryParams.reLeaseCount"
          placeholder="请输入应收租约合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="还款总额合计" prop="rpAmountCount">
        <el-input
          v-model="queryParams.rpAmountCount"
          placeholder="请输入还款总额合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务费" prop="serCharge">
        <el-input
          v-model="queryParams.serCharge"
          placeholder="请输入服务费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收房贷利息合计" prop="agInterestRate">
        <el-input
          v-model="queryParams.agInterestRate"
          placeholder="请输入收房贷利息合计"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过" prop="applyState">
        <el-input
          v-model="queryParams.applyState"
          placeholder="请输入申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="删除标识 0：未删除，1：删除" prop="delFlg">
        <el-input
          v-model="queryParams.delFlg"
          placeholder="请输入删除标识 0：未删除，1：删除"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="常见用户ID" prop="createUserid">
        <el-input
          v-model="queryParams.createUserid"
          placeholder="请输入常见用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新用户ID" prop="updateUserid">
        <el-input
          v-model="queryParams.updateUserid"
          placeholder="请输入更新用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['finance:loan:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['finance:loan:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['finance:loan:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['finance:loan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="loanList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="收房贷申请编号" align="center" prop="sfLoanOrderNo" />
      <el-table-column label="外部合同号" align="center" prop="outOrderNo" />
      <el-table-column label="外部金融产品名称，资方那边的名称" align="center" prop="outProductName" />
      <el-table-column label="商户ID" align="center" prop="businessId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="部门编号" align="center" prop="deptNo" />
      <el-table-column label="收房合同ID" align="center" prop="sfContractId" />
      <el-table-column label="借款金额" align="center" prop="loanAmount" />
      <el-table-column label="借款期限" align="center" prop="monthLimit" />
      <el-table-column label="利率" align="center" prop="rate" />
      <el-table-column label="一次性服务费" align="center" prop="serviceFee" />
      <el-table-column label="金融产品ID" align="center" prop="jrProductId" />
      <el-table-column label="应收租约合计" align="center" prop="reLeaseCount" />
      <el-table-column label="还款总额合计" align="center" prop="rpAmountCount" />
      <el-table-column label="服务费" align="center" prop="serCharge" />
      <el-table-column label="收房贷利息合计" align="center" prop="agInterestRate" />
      <el-table-column label="审核备注" align="center" prop="auditMemo" />
      <el-table-column label="申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过" align="center" prop="applyState" />
      <el-table-column label="删除标识 0：未删除，1：删除" align="center" prop="delFlg" />
      <el-table-column label="常见用户ID" align="center" prop="createUserid" />
      <el-table-column label="更新用户ID" align="center" prop="updateUserid" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['finance:loan:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['finance:loan:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收房贷申请信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="收房贷申请编号" prop="sfLoanOrderNo">
          <el-input v-model="form.sfLoanOrderNo" placeholder="请输入收房贷申请编号" />
        </el-form-item>
        <el-form-item label="外部合同号" prop="outOrderNo">
          <el-input v-model="form.outOrderNo" placeholder="请输入外部合同号" />
        </el-form-item>
        <el-form-item label="外部金融产品名称，资方那边的名称" prop="outProductName">
          <el-input v-model="form.outProductName" placeholder="请输入外部金融产品名称，资方那边的名称" />
        </el-form-item>
        <el-form-item label="商户ID" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="部门编号" prop="deptNo">
          <el-input v-model="form.deptNo" placeholder="请输入部门编号" />
        </el-form-item>
        <el-form-item label="收房合同ID" prop="sfContractId">
          <el-input v-model="form.sfContractId" placeholder="请输入收房合同ID" />
        </el-form-item>
        <el-form-item label="借款金额" prop="loanAmount">
          <el-input v-model="form.loanAmount" placeholder="请输入借款金额" />
        </el-form-item>
        <el-form-item label="借款期限" prop="monthLimit">
          <el-input v-model="form.monthLimit" placeholder="请输入借款期限" />
        </el-form-item>
        <el-form-item label="利率" prop="rate">
          <el-input v-model="form.rate" placeholder="请输入利率" />
        </el-form-item>
        <el-form-item label="一次性服务费" prop="serviceFee">
          <el-input v-model="form.serviceFee" placeholder="请输入一次性服务费" />
        </el-form-item>
        <el-form-item label="金融产品ID" prop="jrProductId">
          <el-input v-model="form.jrProductId" placeholder="请输入金融产品ID" />
        </el-form-item>
        <el-form-item label="应收租约合计" prop="reLeaseCount">
          <el-input v-model="form.reLeaseCount" placeholder="请输入应收租约合计" />
        </el-form-item>
        <el-form-item label="还款总额合计" prop="rpAmountCount">
          <el-input v-model="form.rpAmountCount" placeholder="请输入还款总额合计" />
        </el-form-item>
        <el-form-item label="服务费" prop="serCharge">
          <el-input v-model="form.serCharge" placeholder="请输入服务费" />
        </el-form-item>
        <el-form-item label="收房贷利息合计" prop="agInterestRate">
          <el-input v-model="form.agInterestRate" placeholder="请输入收房贷利息合计" />
        </el-form-item>
        <el-form-item label="审核备注" prop="auditMemo">
          <el-input v-model="form.auditMemo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过" prop="applyState">
          <el-input v-model="form.applyState" placeholder="请输入申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过" />
        </el-form-item>
        <el-form-item label="删除标识 0：未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识 0：未删除，1：删除" />
        </el-form-item>
        <el-form-item label="常见用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入常见用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLoan, getLoan, delLoan, addLoan, updateLoan } from "@/api/finance/loan";

export default {
  name: "Loan",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收房贷申请信息表格数据
      loanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sfLoanOrderNo: null,
        outOrderNo: null,
        outProductName: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        sfContractId: null,
        loanAmount: null,
        monthLimit: null,
        rate: null,
        serviceFee: null,
        jrProductId: null,
        reLeaseCount: null,
        rpAmountCount: null,
        serCharge: null,
        agInterestRate: null,
        auditMemo: null,
        applyState: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        applyState: [
          { required: true, message: "申请状态，1:申请中，2：初审通过，3：初审不通过，4：复审通过，5：复审不通过不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收房贷申请信息列表 */
    getList() {
      this.loading = true;
      listLoan(this.queryParams).then(response => {
        this.loanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sfLoanOrderNo: null,
        outOrderNo: null,
        outProductName: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        sfContractId: null,
        loanAmount: null,
        monthLimit: null,
        rate: null,
        serviceFee: null,
        jrProductId: null,
        reLeaseCount: null,
        rpAmountCount: null,
        serCharge: null,
        agInterestRate: null,
        auditMemo: null,
        applyState: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收房贷申请信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getLoan(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收房贷申请信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateLoan(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addLoan(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收房贷申请信息编号为"' + ids + '"的数据项？').then(function() {
        return delLoan(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('finance/loan/export', {
        ...this.queryParams
      }, `loan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
